package com.bobo.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bobo.auth.common.Result;
import com.bobo.domain.SysRole;
import com.bobo.domain.SysRoleMenu;
import com.bobo.service.SysRoleMenuService;
import com.bobo.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("role")
public class RoleController {


    @Autowired
    SysRoleMenuService sysRoleMenuService;



    @RequestMapping("bindMenu")
    public  Result bindMenu(@RequestBody  SysRoleMenu sysRoleMenu){

       boolean b= sysRoleMenuService.bindMenu(sysRoleMenu);
     return  b?Result.success():Result.fail();
    }

    @Autowired
    SysRoleService roleService;
    @RequestMapping("listPage")
    public Result list(Page page, SysRole role){
        LambdaQueryWrapper<SysRole> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(ObjectUtils.isNotEmpty(role.getName()),SysRole::getName,role.getName());
        Page page1 = roleService.page(page, wrapper);
        return Result.success(page1);
    }

    @RequestMapping("list")
    public Result list(){
        return Result.success(roleService.list());
    }
}
